package com.mxpio.erp.common.mes.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.equipment.entity.Equipment;
import com.mxpio.erp.common.technology.entity.WorkCenter;
import com.mxpio.erp.common.technology.entity.WorkShop;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.BaseEntity;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Data
@Table(name="MB_ERP_MES_WORKORDER_TASK")
@EqualsAndHashCode(callSuper=false)
@Entity
@Schema(description="生产订单-工单-工序任务详情")
@AllArgsConstructor
@NoArgsConstructor
public class ManufactureWorkOrderTask extends BaseEntity {
    private static final long serialVersionUID = 1L;

	/**主键*/
	@Id
    //@Generator
    @Column(name = "TASK_CODE_")
    @Schema(description = "工单任务编号")
    private String taskCode;//String taskCode = "T"+batchTecInfo.getBatchInfoCode()+tecInfo.getProcOrder();//之前的取值逻辑

    /**生产订单主键*/
    @Column(name = "BIZ_NO_")
    @Schema(description = "生产订单单号")
    private String bizNo;

    /**批次号*/
    @Column(name = "BATCH_CODE_")
    @Schema(description = "批次号")
    private String batchCode;

    /**批次号*/
    /*@Column(name = "SN_CODE_")
    @Schema(description = "sn号")
    private String snCode;*/
	/**任务状态*/
	@Dict(dicCode = "MES_WORK_ORDER_TASK_STATUS")//todo 字典及值需确认 开立
    @Schema(description = "任务状态")
    @Column(name = "TASK_STATUS_")
    private String taskStatus;
	/**是否允许派工*/
	@Dict(dicCode = "ERP_COMMON_YESNO")
    @Schema(description = "是否允许派工")
    @Column(name = "DISPATCH_ALLOWED_")
    private String dispatchAllowed;
	/**工序编号*/
    @Schema(description = "工序编号")
    @Column(name = "PROC_CODE_")
    private String procCode;
	/**工序序号*/
    @Schema(description = "工序序号")
    @Column(name = "PROC_ORDER_")
    private Integer procOrder;

    @Column(name = "PROC_GROUP_CODE_")
    @Schema(description  = "工序段编码")
    private String procGroupCode;

    @Column(name = "PROC_GROUP_NAME_" )
    @Schema(description  = "工序段名称")
    private String procGroupName;

	/**物料编码*/
    @Column(name = "ITEM_CODE_")
    @Schema(description = "物料代码")
    private String itemCode;

    @Column(name = "ITEM_NAME_")
    @Schema(description = "物料名称")
    private String itemName ;

    @Column(name = "ITEM_SPEC_")
    @Schema(description = "规格型号")
    private String itemSpec;

    @Column(name = "UNIT_CODE_")
    @Schema(description = "单位编号")
    @Dict(dicCode="ERP_TECH_UNIT_CODE")
    private String unitCode;

    @Column(name = "DRAWING_NO_")
    @Schema(description = "图号")
    private String drawingNo;
	/**计划开工日期*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @Schema(description = "计划开工日期")
    @Column(name = "PO_START_DATE_")
    private Date poStartDate;
	/**计划完工日期*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @Schema(description = "计划完工日期")
    @Column(name = "PO_END_DATE_")
    private Date poEndDate;
	/**实际开工时间*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Schema(description = "实际开工时间")
    @Column(name = "RE_START_DATE_")
    private Date reStartDate;
	/**实际完工时间*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Schema(description = "实际完工时间")
    @Column(name = "RE_END_DATE_")
    private Date reEndDate;

    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    @Schema(description = "完工人ID")
    @Column(name = "RE_END_USER_ID_")
    private String reEndUserId;
	/**设备资产ID*/
    @Column(name = "BASICS_CODE_")
    @Schema(description = "设备资产编号")
    private String basicsCode;

    @Column(name = "EQP_CODE_")
    @Schema(description = "设备编码")//设备
    @Dict(dicCode="eqpCode", dicEntity = Equipment.class, dicText = "eqpName")
    private String eqpCode;
	/**作业单元id*/
    /*@Column(name = "TASK_INFO_ID_")
    @Schema(description = "作业单元id")
    private String taskInfoId;*/
    @Column(name = "WORK_UNIT_CODE_")
    @Schema(description  = "作业单元编码")
    private String workUnitCode;

    @Column(name = "WORK_UNIT_NAME_" )
    @Schema(description  = "作业单元名称")
    private String workUnitName;

    /**派工时间*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @Schema(description = "派工时间")
    @Column(name = "DISPATCH_TIME_")
    private Date dispatchTime;
	/**派工人ID*/
    @Column(name = "DISPATCH_USER_ID_")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    @Schema(description = "派工人ID")
    private String dispatchUserId;

	/**是否暂停(0是1否)*/
    @Column(name = "PRE_TASK_STATUS_")
    @Schema(description = "暂停前状态")
    private String preTaskStatus;
    /**任务索引序号*/
    @Column(name = "TASK_INDEX_")
    @Schema(description = "任务索引序号")
	private Integer taskIndex;
    /**任务条数*/
    @Schema(description = "任务条数")
    @Column(name = "TASK_SIZE_")
    private Integer taskSize;

    @Column(name = "TASK_NUM_")
    @Schema(description = "任务数量")
    private Integer taskNum;//任务数量

    @Column(name = "SCRAP_NUM_")
    @Schema(description = "报废数量")
    private Integer scrapNum;//报废数量

    @Column(name = "COMP_NUM_")
    @Schema(description = "完成数量")
    private Integer compNum;//完成数量

    @Dict(dicCode = "ERP_COMMON_YESNO")
    @Column(name = "FIRST_INSPECT_NEEDED")
    @Schema(description = "是否首检")
    private String firstInspectNeeded;

    // 首检类型
    @Column(name = "FIRST_INSPECT_TYPE")
    @Dict(dicCode = "ERP_MES_PROD_INSP_TYPE")
    @Schema(description = "首检类型")
    private String firstInspectType;

    @Column(name = "FINAL_INSPECT_NEEDED")
    @Schema(description = "是否尾检")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private String finalInspectNeeded;

    // 尾检类型
    @Column(name = "FINAL_INSPECT_TYPE")
    @Dict(dicCode = "mes_check_type")
    @Schema(description = "尾检类型")
    private String finalInspectType;

    @Column(name = "PREPARATION_TIME_" )
    @Schema(description  = "标准准备工时（S）")
    private Integer preparationTime;

    @Column(name = "SINGLE_PIECE_TIME_" )
    @Schema(description  = "单件标准工时（S）")
    private Integer singlePieceTime;

    @Column(name = "ROUT_PROC_ID_" )
    @Schema(description  = "产品工艺路线工序明细行ID")
    private String routProcId;//

    @Column(name = "ORDER_ROUT_PROC_ID_" )
    @Schema(description  = "订单工艺路线工序明细行ID")//ManufactureOrderRoute 对应id
    private String orderRoutProcId;

    @Dict(dicCode = "ERP_MES_DISPATCH_MODE")
    @Column(name = "DISPATCH_MODE_")
    @Schema(description = "派工模式")
    private String dispatchMode;

    @Column(name = "MAIN_WORKSHOP_")
    @Schema(description = "主制车间")
    @Dict(dicCode = "workShopCode",dicEntity = WorkShop.class,dicText = "workShopName")
    private String mainWorkshop;

    @Column(name = "WORK_CENTER_CODE_")
    @Schema(description = "工作中心")
    @Dict(dicCode = "workCenterCode",dicEntity = WorkCenter.class,dicText = "workCenterName")
    private String workCenterCode;

    /**是否存在质检单检验中*/
    @Dict(dicCode = "ERP_COMMON_YESNO")
    @Schema(description = "是否存在质检单检验中")
    @Column(name = "INSPECTION_BILL_CHECKING_", columnDefinition = "varchar(2) default '0'")
    private String inspectionBillChecking;

    /*public ManufactureWorkOrderTask(ManufactureWorkOrder order) {
        this.bizNo = order.getBizNo();
        this.batchCode = order.getBatchCode();
    }*/
}
